#cmake版本号
cmake_minimum_required(VERSION 2.6)

#自动获取当前文件夹名称作为项目名变量
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
MESSAGE("include folder: "${PROJECT_NAME})

#项目
project(${PROJECT_NAME})

#添加语言定义
add_definitions(-std=c++11)

#忽略警告
add_definitions(-w)

#添加调试选项
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -oo -Wall -g -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -03 -Wall")

#检索子目录宏
#append all subdir of ${targetdir} to ${subdirlist}
macro(SUBDIRLIST_MACRO subdirlist targetdir)
    file(GLOB children ${targetdir}/*)
    set(dirlist "")
    foreach(child ${children})
        file(RELATIVE_PATH child_name ${targetdir} ${child})
        if(IS_DIRECTORY ${targetdir}/${child_name})
            list(APPEND dirlist ${targetdir}/${child_name})
        endif()
    endforeach(child ${children})
    list(APPEND ${subdirlist} ${dirlist})
endmacro()

#add ${targetdir} and all subdir of ${targetdir} to ${all_subdirlist}
macro(ALL_SUBDIRLIST_MACRO all_subdirlist targetdir)
    set(queue ${targetdir})
    foreach (loop_var RANGE 9999999)
        list(LENGTH queue q_len)
        #message("queue: ${queue}")
        if(${q_len} STREQUAL "0")
            break()
        endif()
        list (POP_FRONT queue front)
        #message ("queue: ${queue}")
        message ("front: ${front}")
        List (APPEND ${all_subdirlist} ${front}) 
        SUBDIRLIST_MACRO(queue ${front})
        #message("queue: ${queue}")
    endforeach()
endmacro()

    #添加子目录
add_subdirectory(./src)
